import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/controllers/start_page_controller.dart';
import 'package:xinxuan/router/app_routers.dart';

class UserAgreementDialog extends StatelessWidget {

  final StartPageController startPageController = Get.find();
  final CommonPageController commonPageController = Get.find();

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Center(
        child: Container(
          width: 320.w,
          child: Stack(
            children: [
              Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  SizedBox(height: 92.h),
                  Container(
                    decoration: BoxDecoration(
                      color: bgWhiteColor,
                      borderRadius: BorderRadius.circular(8.w)
                    ),
                    child: Column(
                      children: [
                        SizedBox(height: 86.h),
                        Container(
                          height: 46.h,
                          alignment: Alignment.center,
                          child: Text(
                            '温馨提示',
                            style: TextStyle(
                              color: textBlackColor,
                              fontSize: 16.sp,
                              fontWeight: FontWeight.bold
                            ),
                          )
                        ),
                        Container(
                          padding: EdgeInsets.only(left: 20.w, right: 20.w, bottom: 12.h),
                          child: Text.rich(
                            TextSpan(
                              text: '欢迎使用APP，在你使用时，需要连接数据网络或者WIFI,产生的流量请咨询当地运营商，非常重视你的隐私保护和个人信息保护。在使用APP服务前，请认真阅读',
                              style: TextStyle(
                                color: textBlackColor,
                                fontSize: 14.sp
                              ),
                              children: [
                                WidgetSpan(
                                  child: InkWellUtil.shakeProofInkWell(Text(
                                    '《用户服务协议》',
                                    style: TextStyle(
                                      color: mainTextColor,
                                      fontSize: 14.sp
                                    ),
                                  ), () {
                                    Get.back();
                                    Get.toNamed(
                                      '${AppRouters.COMMON_PAGE}${AppRouters.ARTICLE_DETAIL_PAGE}',
                                      arguments: {
                                        'articleId': 3,
                                        'title': '用户协议'
                                      }
                                    )!.then((res) {
                                      startPageController.initStart();
                                    });
                                  })
                                ),
                                TextSpan(
                                  text: '及',
                                  style: TextStyle(
                                    color: mainTextColor,
                                    fontSize: 14.sp
                                  ),
                                ),
                                WidgetSpan(
                                  child: InkWellUtil.shakeProofInkWell(Text(
                                    '《隐私政策》',
                                    style: TextStyle(
                                      color: mainTextColor,
                                      fontSize: 14.sp
                                    ),
                                  ), () {
                                    Get.back();
                                    Get.toNamed(
                                      '${AppRouters.COMMON_PAGE}${AppRouters.ARTICLE_DETAIL_PAGE}',
                                      arguments: {
                                        'articleId': 2,
                                        'title': '隐私政策'
                                      }
                                    )!.then((res) {
                                      startPageController.initStart();
                                    });
                                  })
                                ),
                                TextSpan(
                                  text: '，全部条款。你同意并接受全部条款后开始使用我们的服务。',
                                  style: TextStyle(
                                    color: textBlackColor,
                                    fontSize: 14.sp
                                  ),
                                ),
                              ]
                            )
                          )
                        ),
                        Container(
                          height: 55.h,
                          decoration: BoxDecoration(
                            border: Border(
                              top: BorderSide(
                                color: lineColor,
                                width: .5.h
                              )
                            ),
                          ),
                          child: Row(
                            children: [
                              _btnWidget(
                                text: '不同意', 
                                color: textSubtitleColor, 
                                width: 160,
                                onTop: () {
                                  exit(0);
                                } 
                              ),
                               _btnWidget(
                                text: '同意', 
                                color: mainTextColor, 
                                width: 159,
                                showBorder: false,
                                onTop: () {
                                  commonPageController.consentAuthorization();
                                } 
                              )
                            ],
                          ),
                        )
                      ],
                    ),
                  )
                ],
              ),
              Positioned(
                top: 0,
                child: Image.asset(
                  'assets/icons/icon_agreement_dialog.png',
                  width: 320.w,
                  height: 178.h,
                  fit: BoxFit.fill,
                )
              )
            ],
          ),
        ),
      ),
    );
  }

  /// 底部按钮
  Widget _btnWidget({ required String text, required Color color, required Function onTop, required int width, bool showBorder = true }) {
    return InkWellUtil.shakeProofInkWell(Container(
      width: width.w,
      height: 55.h,
      alignment: Alignment.center,
      decoration: BoxDecoration(
        border: Border(
          right: showBorder ? BorderSide(
            width: .5,
            color: lineColor
          ) : BorderSide.none
        ),
      ),
      child: Text(
        text,
        style: TextStyle(
          color: color,
          fontSize: 16.sp
        ),
      ),
    ), () => onTop(),
    hoverColor: Colors.transparent,
    splashColor: Colors.transparent,
    highlightColor: Colors.transparent);
  }
}